import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/layout/index.vue'

export default createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      // Layout 没必要使用路由懒加载，因为一上来就是需要看到的
      component: Layout,
      children: [
        {
          path: '', // 空字符串就表示 Layout 组件的默认子路由
          component: () => import('@/views/home/index.vue'),
        },
        {
          // :id 表示后续需要作为参数传递的，例如 /category/18000，18000 就是 id
          path: '/category/:id',
          component: () => import('@/views/category/index.vue'),
        },
        {
          // :id 表示后续需要作为参数传递的，例如 /category/sub/18000，18000 就是 id
          path: '/category/sub/:id',
          component: () => import('@/views/category/sub.vue'),
        },
        {
          // 商品详情
          path: '/goods/:id',
          component: () => import('@/views/goods/index.vue'),
        },
      ],
    },
    {
      path: '/login',
      component: () => import('@/views/login/index.vue'),
    },
    {
      path: '/playground',
      component: () => import('@/views/playground/index.vue'),
    },
  ],
  scrollBehavior: () => ({
    top: 0,
  }),
})
